package study.concurrent.thread.support.session;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UserContext {

//    private static final ThreadLocal<UserInfo> LOCAL = new ThreadLocal<>();
    private static final TransmittableThreadLocal<UserInfo> LOCAL = new TransmittableThreadLocal<>();

    public static void set(UserInfo userInfo) {
        LOCAL.set(userInfo);
    }

    public static UserInfo get() {
        //log.info("get 线程名: {}", Thread.currentThread().getName());
        return LOCAL.get();
    }

    public static void remove() {
        LOCAL.remove();
    }
}
